<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //throw 抛出自定义错误
        try {
            throw "主动抛出错误";
        } catch (e) {
            console.log("报错信息：" + e);
        } finally {
            console.log(123);
        }
        console.log(456);



        //例2
        function getRectArea(width, height) {
            if (isNaN(width) || isNaN(height)) {
                throw "Parameter is not a number!";
            }
        }

        try {
            getRectArea(3, 'A');
        } catch (e) {
            console.log(e); // expected output: "Parameter is not a number!"
        }

        //例3
        try {
            // throw 49; // 抛出一个数值异常
            // throw 51; // 抛出一个数值异常
        } catch (e) {
            if (e <= 50) {
                // 异常在 1-50 之间时，直接处理
                console.log("异常在 1-50 之间时，直接处理");
            } else {
                // 异常无法处理，重新抛出
                throw e;
            }
        }
    </script>
</body>

</html>